{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a2fce5fc-323f-47dc-addd-840ec6bc2adc",
   "metadata": {},
   "source": [
    "# Bell State Preparation\n",
    "\n",
    "The `prepare_bell_state` function creates one of the four Bell states\n",
    "\n",
    "$$\n",
    "\\phi_{+} = \\frac{1}{2} \\left(|00\\rangle + |11\\rangle \\right)\n",
    "$$\n",
    "\n",
    "$$\n",
    "\\phi_{-} = \\frac{1}{2} \\left(|00\\rangle - |11\\rangle \\right)\n",
    "$$\n",
    "\n",
    "$$\n",
    "\\psi_{+} = \\frac{1}{2} \\left(|01\\rangle + |10\\rangle \\right)\n",
    "$$\n",
    "\n",
    "$$\n",
    "\\psi_{-} = \\frac{1}{2} \\left(|01\\rangle - |10\\rangle \\right)\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d53ede39-4a34-4bd5-aef1-f54de93d3605",
   "metadata": {},
   "source": [
    "Function: `prepare_bell_state`\n",
    "\n",
    "Arguments:\n",
    "\n",
    "- `state_num: CInt`\n",
    "- `q: Output[QArray[QBit]]`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "14a3ddb8-1a5a-49ba-85b4-b8cf18233c98",
   "metadata": {},
   "source": [
    "## Example\n",
    "The `prepare_bell_state` function creates \n",
    "\n",
    "$$\n",
    "\\psi_{+} = \\frac{1}{2} \\left(|01\\rangle + |10\\rangle \\right)\n",
    "$$\n",
    "\n",
    "`state_num` is set to 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e5c0df9f-8cc8-4fef-b9e4-44e26a40af34",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-05-07T13:25:56.657877Z",
     "iopub.status.busy": "2024-05-07T13:25:56.657433Z",
     "iopub.status.idle": "2024-05-07T13:25:59.424150Z",
     "shell.execute_reply": "2024-05-07T13:25:59.423499Z"
    }
   },
   "outputs": [],
   "source": [
    "from classiq import Output, QArray, QBit, create_model, prepare_bell_state, qfunc\n",
    "\n",
    "\n",
    "@qfunc\n",
    "def main(x: Output[QArray[QBit]]):\n",
    "    prepare_bell_state(2, x)\n",
    "\n",
    "\n",
    "qmod = create_model(main)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ca1341a7-5465-4ff2-b037-7c6bf1f5a06e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-05-07T13:25:59.427021Z",
     "iopub.status.busy": "2024-05-07T13:25:59.426679Z",
     "iopub.status.idle": "2024-05-07T13:26:00.854529Z",
     "shell.execute_reply": "2024-05-07T13:26:00.853704Z"
    }
   },
   "outputs": [],
   "source": [
    "from classiq import synthesize, write_qmod\n",
    "\n",
    "write_qmod(qmod, \"prepare_bell_state\")\n",
    "qprog = synthesize(qmod)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
